package com.yilin.medical.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yilin.medical.R;
import com.yilin.medical.activity.YiYuanDetailsActivity;
import com.yilin.medical.activity.ZhuanJiaDetailsActivity;
import com.yilin.medical.model.GuoJiGuoNeiZhuanZhenBean;
/**
 * 肿瘤adapter
 * @author lijianqun
 *
 */
public class GuoJiGuoNeiZhuanZhenAdapter extends BaseAdapter {
	private Context context;
	private List<GuoJiGuoNeiZhuanZhenBean> list;

	public GuoJiGuoNeiZhuanZhenAdapter(Context context, List<GuoJiGuoNeiZhuanZhenBean> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.listitem_guojiguoneizhuanzhen,
					null);
			holder.iv = (ImageView) convertView.findViewById(R.id.iv);
			holder.tv_catalog = (TextView) convertView
					.findViewById(R.id.tv_catalog);
			holder.tv_describe = (TextView) convertView
					.findViewById(R.id.tv_describe);
			holder.ll_item = (LinearLayout) convertView
					.findViewById(R.id.ll_item);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.ll_item.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = null;
			if (position <=4 ) {//跳到医院详情
				intent = new Intent(context, YiYuanDetailsActivity.class);
				context.startActivity(intent);
			}else {//跳到医生详情
				intent = new Intent(context, ZhuanJiaDetailsActivity.class);
				context.startActivity(intent);
			}
				
			};
		});
		/*if (position ==0||position ==4) {
			holder.tv_catalog.setVisibility(View.VISIBLE);
			if (position ==0) {
				holder.tv_catalog.setText("医院推荐");
			}if (position ==4) {
				holder.tv_catalog.setText("医生推荐");
			}
		}
		else {
			holder.tv_catalog.setVisibility(View.GONE);
		}*/
		
		if (position ==0) {
			holder.tv_catalog.setVisibility(View.VISIBLE);
			holder.tv_catalog.setText("医院推荐");
		}
		else if (position ==4) {
			holder.tv_catalog.setVisibility(View.VISIBLE);
			holder.tv_catalog.setText("医生推荐");
		}else {
			holder.tv_catalog.setVisibility(View.GONE);
		}
		
		return convertView;
	}

	class ViewHolder {
		ImageView iv;
		TextView tv_catalog, tv_describe;
		LinearLayout ll_item;
	}

}
